package org.login.obj;

import io.netty.channel.Channel;
import org.common.netty.Pack;
import org.common.netty.PackCodec;
import org.login.defs.ConnectStatusEnum;

/**
 * 连接数据
 */
public class ConnectContext {
    private final long connectId;
    private final Channel clientChannel;
    // 账号id
    private long accountId;
    // 角色id
    private long roleId;
    // 分配的游戏服id
    private int gameServerId;
    // 分配的游戏服channel
    private Channel gameServerChannel;
    // 账号名
    private String accountName;
    // 账号状态 0:未登录 1:账号已登录 2:角色已登录
    private ConnectStatusEnum status = ConnectStatusEnum.NOT_LOGIN;

    public ConnectContext(long connectId, Channel channel) {
        this.connectId = connectId;
        this.clientChannel = channel;
    }

    public long getConnectId() {
        return connectId;
    }

    public Channel getClientChannel() {
        return clientChannel;
    }

    public long getAccountId() {
        return accountId;
    }

    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public ConnectStatusEnum getStatus() {
        return status;
    }

    public void setStatus(ConnectStatusEnum status) {
        this.status = status;
    }

    public int getGameServerId() {
        return gameServerId;
    }

    public void setGameServerId(int gameServerId) {
        this.gameServerId = gameServerId;
    }

    public Channel getGameServerChannel() {
        return gameServerChannel;
    }

    public void setGameServerChannel(Channel gameServerChannel) {
        this.gameServerChannel = gameServerChannel;
    }

    public long getRoleId() {
        return roleId;
    }

    public void setRoleId(long roleId) {
        this.roleId = roleId;
    }

    /**
     * 推送消息到客户端
     */
    public void push(Pack pack) {
        byte[] data = PackCodec.encode(pack);
        clientChannel.writeAndFlush(data);
    }
}
